package org.greatstorm.event;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GSSynEventChannel implements EventChannel {
	Map<Event, List<EventHandler>> channels = new HashMap<Event, List<EventHandler>>();

	@Override
	public void broadcaster(Event e) {
		List<EventHandler> handlerList = channels.get(e);

		for (EventHandler h : handlerList) {
			h.handle(e);
		}
	}

	@Override
	public void register(Event e, EventHandler handler) {
		List<EventHandler> handlerList = channels.get(e);

		if (handlerList == null) {
			handlerList = new ArrayList<EventHandler>();
		}

		handlerList.add(handler);

		channels.put(e, handlerList);
	}

	@Override
	public int getEventCnt() {
		return channels.keySet().size();
	}
}
